home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageAxisRotation / ImageAxisRotation.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.9 KB  |  427 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.image.MemoryImageSource;
  14. import java.awt.image.PixelGrabber;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18.  
  19. public class ImageAxisRotation extends Applet implements Runnable, MouseListener {
  20.    boolean loaded;
  21.    Thread thread;
  22.    Image image;
  23.    Image buffer;
  24.    // $FF: renamed from: b java.awt.Graphics
  25.    Graphics field_0;
  26.    // $FF: renamed from: wi int
  27.    int field_1;
  28.    // $FF: renamed from: he int
  29.    int field_2;
  30.    int wiIm;
  31.    int heIm;
  32.    int pause = 20;
  33.    static int[] pix;
  34.    static int[] pixnew;
  35.    int yIni;
  36.    double angle = (double)0.1875F;
  37.    double angleStep = 0.15707963267948966;
  38.    private Color backColor;
  39.    private String statusBarText;
  40.    private AudioClip sound;
  41.    private AudioClip clicSound;
  42.    private AudioClip enterSound;
  43.    private boolean loopSound;
  44.    private String link;
  45.    // $FF: renamed from: fm java.awt.FontMetrics
  46.    private FontMetrics field_3;
  47.    private String enterText;
  48.    private boolean isEnterTextEnabled;
  49.    private int wiEnterText;
  50.    private int enterTextHeight;
  51.    private Color enterTextColor;
  52.    private int decx;
  53.    private int decy;
  54.  
  55.    public String getAppletInfo() {
  56.       return "Name: ImageAxisRotation\r\nAuthor: Taiji Software\r\n";
  57.    }
  58.  
  59.    public ImageAxisRotation() {
  60.       this.backColor = Color.black;
  61.       ((Component)this).addMouseListener(this);
  62.    }
  63.  
  64.    public void register() {
  65.       try {
  66.          URL u = new URL("http://www.taijisoftware.com");
  67.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  68.          this.stop();
  69.       } catch (Exception e) {
  70.          System.out.println(e);
  71.          this.stop();
  72.       }
  73.    }
  74.  
  75.    public void init() {
  76.       String codeBase = null;
  77.  
  78.       try {
  79.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  80.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  81.          codeBase = codeBase.toUpperCase();
  82.       } catch (Exception var11) {
  83.       }
  84.  
  85.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  86.          String regCode = ((Applet)this).getParameter("registration_code");
  87.          if (regCode == null) {
  88.             regCode = ((Applet)this).getParameter("reg_domain");
  89.             if (regCode == null) {
  90.                this.register();
  91.             } else {
  92.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  93.                   codeBase = "WWW." + codeBase;
  94.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  95.                   codeBase = codeBase.substring(4);
  96.                }
  97.  
  98.                char[] chars = new char[codeBase.length()];
  99.                codeBase.getChars(0, codeBase.length(), chars, 0);
  100.                String key = new String("haricot");
  101.                char[] chars2 = new char[key.length()];
  102.                key.getChars(0, key.length(), chars2, 0);
  103.  
  104.                for(int i = 0; i < codeBase.length(); ++i) {
  105.                   int j;
  106.                   if (i >= key.length()) {
  107.                      j = i - key.length() * (i / key.length());
  108.                   } else {
  109.                      j = i;
  110.                   }
  111.  
  112.                   chars[i] += chars2[j];
  113.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  114.                }
  115.  
  116.                String res = new String(chars);
  117.                if (!res.equalsIgnoreCase(regCode)) {
  118.                   this.register();
  119.                }
  120.             }
  121.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  122.             this.register();
  123.          }
  124.       }
  125.  
  126.       this.getParameters();
  127.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  128.       MediaTracker tracker = new MediaTracker(this);
  129.       tracker.addImage(this.image, 0);
  130.  
  131.       try {
  132.          tracker.waitForAll();
  133.          tracker.isErrorAny();
  134.       } catch (Exception e) {
  135.          System.err.println(e);
  136.       }
  137.  
  138.       if (!this.loaded) {
  139.          this.stop();
  140.       }
  141.  
  142.       this.wiIm = this.image.getWidth(this);
  143.       this.heIm = this.image.getHeight(this);
  144.       this.decx = (this.field_1 - this.wiIm) / 2;
  145.       this.decy = (this.field_2 - this.heIm) / 2;
  146.       this.yIni = this.heIm / 2;
  147.       pix = new int[this.wiIm * this.heIm];
  148.       pixnew = new int[this.wiIm * this.heIm];
  149.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  150.  
  151.       try {
  152.          pixg.grabPixels();
  153.       } catch (InterruptedException var9) {
  154.       }
  155.  
  156.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  157.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  158.       this.field_0 = this.buffer.getGraphics();
  159.       this.field_0.setColor(this.enterTextColor);
  160.       String fontName = ((Applet)this).getParameter("enter_text_font");
  161.       if (fontName == null) {
  162.          fontName = "TimesRoman";
  163.       }
  164.  
  165.       int style = 1;
  166.       String s = ((Applet)this).getParameter("enter_text_style");
  167.       if (s != null) {
  168.          if (s.equals("bold")) {
  169.             style = 1;
  170.          } else if (s.equals("italic")) {
  171.             style = 2;
  172.          } else if (s.equals("bold_italic")) {
  173.             style = 3;
  174.          } else {
  175.             style = 0;
  176.          }
  177.       }
  178.  
  179.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  180.       this.field_3 = this.field_0.getFontMetrics();
  181.       if (this.enterText != null) {
  182.          this.wiEnterText = this.field_3.stringWidth(this.enterText);
  183.       }
  184.  
  185.       if (this.sound != null) {
  186.          if (this.loopSound) {
  187.             this.sound.loop();
  188.             return;
  189.          }
  190.  
  191.          this.sound.play();
  192.       }
  193.  
  194.    }
  195.  
  196.    public void getParameters() {
  197.       this.field_1 = ((Component)this).getSize().width;
  198.       this.field_2 = ((Component)this).getSize().height;
  199.       String s = ((Applet)this).getParameter("pause");
  200.       if (s != null) {
  201.          this.pause = Integer.parseInt(s);
  202.       }
  203.  
  204.       s = ((Applet)this).getParameter("angle");
  205.       if (s != null) {
  206.          this.angleStep = Math.PI / new Double(s);
  207.       }
  208.  
  209.       ((Component)this).setBackground(this.getColor("background_color"));
  210.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  211.       s = ((Applet)this).getParameter("sound_name");
  212.       if (s != null) {
  213.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  214.       }
  215.  
  216.       s = ((Applet)this).getParameter("loop_sound");
  217.       if (s != null) {
  218.          if (s.equals("yes")) {
  219.             this.loopSound = true;
  220.          } else {
  221.             this.loopSound = false;
  222.          }
  223.       }
  224.  
  225.       s = ((Applet)this).getParameter("clic_sound_name");
  226.       if (s != null) {
  227.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  228.       }
  229.  
  230.       s = ((Applet)this).getParameter("enter_sound_name");
  231.       if (s != null) {
  232.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  233.       }
  234.  
  235.       this.link = ((Applet)this).getParameter("link");
  236.       this.enterText = ((Applet)this).getParameter("enter_text");
  237.       s = ((Applet)this).getParameter("enter_text_height");
  238.       if (s != null) {
  239.          this.enterTextHeight = Integer.parseInt(s);
  240.       }
  241.  
  242.       this.enterTextColor = this.getColor("enter_text_color");
  243.       if (this.enterTextColor == null) {
  244.          this.enterTextColor = Color.white;
  245.       }
  246.  
  247.    }
  248.  
  249.    public Color getColor(String param) {
  250.       String s = ((Applet)this).getParameter(param);
  251.       if (s != null) {
  252.          if (s.substring(0, 1).equals("#")) {
  253.             s = s.substring(1);
  254.             int i = Integer.parseInt(s, 16);
  255.             return new Color(i);
  256.          } else {
  257.             return null;
  258.          }
  259.       } else {
  260.          return null;
  261.       }
  262.    }
  263.  
  264.    public void start() {
  265.       if (this.thread == null) {
  266.          this.thread = new Thread(this);
  267.          this.thread.start();
  268.       }
  269.  
  270.    }
  271.  
  272.    public void stop() {
  273.       if (this.thread != null) {
  274.          this.thread = null;
  275.       }
  276.  
  277.       if (this.sound != null) {
  278.          this.sound.stop();
  279.       }
  280.  
  281.    }
  282.  
  283.    public final void run() {
  284.       Thread.currentThread().setPriority(4);
  285.  
  286.       while(true) {
  287.          ((Component)this).repaint();
  288.  
  289.          try {
  290.             Thread.sleep((long)this.pause);
  291.          } catch (InterruptedException var1) {
  292.          }
  293.  
  294.          pixnew = new int[this.wiIm * this.heIm];
  295.          this.calculatePixels();
  296.          this.angle += this.angleStep;
  297.          if (this.angle > (Math.PI * 2D)) {
  298.             this.angleStep = -this.angleStep;
  299.          }
  300.       }
  301.    }
  302.  
  303.    public final void paint(Graphics g) {
  304.       if (!this.loaded) {
  305.          this.field_0.setColor(Color.white);
  306.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  307.          this.loaded = true;
  308.       } else {
  309.          if (this.image != null) {
  310.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  311.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  312.             if (this.isEnterTextEnabled) {
  313.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  314.             }
  315.  
  316.             this.image = null;
  317.          }
  318.  
  319.          g.drawImage(this.buffer, 0, 0, this);
  320.       }
  321.    }
  322.  
  323.    public final void update(Graphics g) {
  324.       this.paint(g);
  325.    }
  326.  
  327.    private final void calculatePixels() {
  328.       for(int i = 0; i < this.heIm; ++i) {
  329.          for(int j = 0; j < this.wiIm; ++j) {
  330.             int k = pix[i * this.wiIm + j];
  331.             int jj = i - this.yIni;
  332.             int ii = (int)((double)jj * Math.cos(this.angle));
  333.             ii += this.yIni;
  334.  
  335.             try {
  336.                pixnew[ii * this.wiIm + j] = k;
  337.             } catch (Exception var6) {
  338.             }
  339.          }
  340.       }
  341.  
  342.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  343.    }
  344.  
  345.    public URL giveURL(String url) {
  346.       try {
  347.          if (url.toUpperCase().startsWith("HTTP")) {
  348.             return new URL(url);
  349.          } else if (url.toUpperCase().startsWith("FTP")) {
  350.             int p = url.indexOf(":");
  351.             int p2 = url.indexOf(":", p + 1);
  352.             if (p2 != -1) {
  353.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  354.             }
  355.  
  356.             p = url.indexOf("%40");
  357.             if (p != -1) {
  358.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  359.             }
  360.  
  361.             return new URL(url);
  362.          } else {
  363.             return new URL(((Applet)this).getCodeBase(), url);
  364.          }
  365.       } catch (MalformedURLException e) {
  366.          System.out.println(e);
  367.          return null;
  368.       }
  369.    }
  370.  
  371.    public void mouseClicked(MouseEvent e) {
  372.    }
  373.  
  374.    public void mouseEntered(MouseEvent e) {
  375.       if (this.enterText != null) {
  376.          this.isEnterTextEnabled = true;
  377.          this.field_0.setColor(this.enterTextColor);
  378.          ((Component)this).repaint();
  379.       }
  380.  
  381.       if (this.statusBarText != null) {
  382.          ((Applet)this).showStatus(this.statusBarText);
  383.       }
  384.  
  385.       if (this.enterSound != null) {
  386.          this.enterSound.play();
  387.       }
  388.  
  389.       if (this.link != null) {
  390.          ((Component)this).setCursor(new Cursor(12));
  391.       }
  392.  
  393.    }
  394.  
  395.    public void mouseExited(MouseEvent e) {
  396.       if (this.isEnterTextEnabled) {
  397.          this.isEnterTextEnabled = false;
  398.          ((Component)this).repaint();
  399.       }
  400.  
  401.       if (this.link != null) {
  402.          ((Component)this).setCursor(new Cursor(0));
  403.       }
  404.  
  405.    }
  406.  
  407.    public void mousePressed(MouseEvent e) {
  408.       if (this.clicSound != null) {
  409.          this.clicSound.play();
  410.       }
  411.  
  412.       if (this.link != null) {
  413.          String target = ((Applet)this).getParameter("target");
  414.          if (target == null) {
  415.             target = "_blank";
  416.          }
  417.  
  418.          URL u = this.giveURL(this.link);
  419.          ((Applet)this).getAppletContext().showDocument(u, target);
  420.       }
  421.  
  422.    }
  423.  
  424.    public void mouseReleased(MouseEvent e) {
  425.    }
  426. }
  427.